using System;
using System.Windows.Forms;

namespace CombatTracker.Controls
{
  public partial class InitiativeQuery : Form
  {
    public int Bonus
    {
      get { return int.Parse(txtBonus.Text); }
    }

    public int Roll
    {
      get { return int.Parse(txtRoll.Text); }
    }

    public InitiativeQuery(string name, int bonus)
    {
      InitializeComponent();

      lblName.Text = name + ":";
      txtBonus.Text = bonus.ToString();
    }

    private void btnAccept_Click(object sender, EventArgs e)
    {
      int bonus = 0;
      int roll = 0;

      if (int.TryParse(txtBonus.Text, out bonus) && int.TryParse(txtRoll.Text, out roll))
      {
        if (((1 + bonus) <= roll) && (roll <= (20 + bonus)))
        {
          DialogResult = DialogResult.OK;
          Close();
        }
        else
        {
          MessageBox.Show("Error: Initiative must be between " + (1 + bonus) + " and " + (20 + bonus),
                          "Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
      }
    }
  }
}